package com.app.mingluxing.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.app.mingluxing.R;
import com.app.mingluxing.bean.WhiteListResult;
import com.app.mingluxing.utils.CommonUtils;

import java.util.List;

/**
 * 手环白名单adapter
 * Created by Aaron on 15/8/7.
 */
public class WhiteListAdapter extends BaseAdapter {


    private Context context;
    public List<WhiteListResult.White> whiteList;
//    private boolean isDelete;
//
//
//    public void setIsDelete(boolean isDelete) {
//        this.isDelete = isDelete;
//    }

//    //0是刚进来的模式  1 是删除模式  2 是正常模式(非删除模式)
//    private int style = 0;
//
//    private ObjectAnimator animator;

    public WhiteListAdapter(Context context,List<WhiteListResult.White> whiteList) {
        this.context = context;
        this.whiteList=whiteList;
    }

//    public void setStyle(int style) {
//        this.style = style;
//    }
    public void setData(List<WhiteListResult.White> whiteList){
        this.whiteList=whiteList;
    }
    @Override
    public int getCount() {
        return whiteList.size();
    }

    @Override
    public Object getItem(int position) {

        return whiteList.get(position);
    }

    @Override
    public long getItemId(int position) {

        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_safe_area, null);
            viewHolder = new ViewHolder();

            viewHolder.tv_left_item = (TextView) convertView.findViewById(R.id.tv_left_item);
            viewHolder.tv_right_item = (TextView) convertView.findViewById(R.id.tv_right_item);

//            viewHolder.ll_left = (LinearLayout) convertView.findViewById(R.id.ll_left);
//            viewHolder.ll_item_total = (LinearLayout) convertView.findViewById(R.id.ll_item_total);
//            viewHolder.iv_delete = (ImageView) convertView.findViewById(R.id.iv_delete);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

//        if (isDelete) {
//            float x = viewHolder.rl_left.getTranslationX();
//            ObjectAnimator animator = ObjectAnimator.ofFloat(viewHolder.ll_left, "translationX", 0, DensityUtil.dip2px(context,50));
//            animator.setDuration(500);
//            animator.start();
//
//        }

//        switch (style) {
//
//            case 0:
//
//                animator = ObjectAnimator.ofFloat(viewHolder.ll_left, "translationX", 0, -DensityUtil.dip2px(context, 50));
//                animator.setDuration(0);
//
//                break;
//
//            case 1:
//
//                animator = ObjectAnimator.ofFloat(viewHolder.ll_left, "translationX", -DensityUtil.dip2px(context, 50), 0);
//                animator.setDuration(500);
//
//                break;
//
//            case 2:
//                animator = ObjectAnimator.ofFloat(viewHolder.ll_left, "translationX", 0, -DensityUtil.dip2px(context, 50));
//                animator.setDuration(500);
//
//                break;
//
//        }
//
//        animator.start();
        if (whiteList==null)
            return convertView;

        viewHolder.tv_left_item.setText(CommonUtils.isNull(whiteList.get(position).name)?"":whiteList.get(position).name);
        viewHolder.tv_right_item.setText(CommonUtils.isNull(whiteList.get(position).phoneNum)?"":whiteList.get(position).phoneNum);
//       final LinearLayout ll = viewHolder.ll_item_total;
//
//        viewHolder.iv_delete.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                LogUtil.e("TAG", "删除点击事件==>" + position);
//                float translationX = ll.getTranslationX();
//
//                ObjectAnimator anima = ObjectAnimator.ofFloat(ll, "translationX", 0, -DensityUtil.dip2px(context, 50));
//                anima.setDuration(500);
//                anima.start();
//
//            }
//        });

        return convertView;
    }

    private class ViewHolder {
        TextView tv_left_item;
        TextView tv_right_item;
//        LinearLayout ll_left;
//        LinearLayout ll_item_total;
//        ImageView iv_delete;
    }

}
